<?php
namespace app\api\controller;
use think\Controller;
use think\Db;
use think\db\Where;
use think\helper\Time;
use think\helper\Hash;
use app\common\lib\RedisServer;
class Home extends Controller
{

    public $uid='';
    public function initialize(){
        $action = $this->request->action();
        if($action == 'pay_balance' || $action=='adpot_order_list' ||  $action=='butcher' || $action=='feed' || $action=='address' || $action=='address_list' || $action=='edit_address' || $action=='delete_address'|| $action=='is_ture'  || $action=='bath' || $action=='add_car' || $action=='delete_car'  ||  $action=='car_list' || $action=='edit_car' || $action=='present_order' || $action=='goods_order'){
            $uid = Yanzhengs();

//            dump($uid);die;
            if ($uid==0 || $uid==''){
                echo json_encode(['code'=>201,'msg'=>'请登录']);die;
            }
            $this->uid=$uid;
            $action='/'.request()->module().'/'.request()->controller().'/'.request()->action();
            $check = RedisServer::lock($uid.$action);
            if ($check==false){
                echo json_encode(['code'=>1,'msg'=>'网络错误！']);die;
            }
        }
    }
    protected function ajaxReturn($code,$msg,$array2=array()){
        $array1 = array('code'=>$code,'msg'=>$msg);
        $data = array_merge($array1,$array2);
        $action='/'.request()->module().'/'.request()->controller().'/'.request()->action();
        @RedisServer::unlock($this->uid.$action);
        return json($data);
    }

    public function car_list(){
        $page=input('post.page/d')?input('post.page/d'):1;
        $type=input('post.type/d')?input('post.type/d'):0;//0钣喷工厂，1快捷保养，2紧急救援
        $name=input('post.name');
        $province=input('post.province');
        $city=input('post.city');
        $area=input('post.area');
        $where=[];
        $where[]=['del','eq',0];
        $where[]=['flag','eq',1];
        $where[]=['shoptype','eq',$type];
        if (!empty($province)){
            $where[]=['province','eq',$province];
        }
        if (!empty($city)){
            $where[]=['city','eq',$city];
        }
        if (!empty($area)){
            $where[]=['area','eq',$area];
        }
        if (!empty($name)){
            $where[]=['shopname','like','%'.$name.'%'];
        }
        $url = config('weburl');
        $shop=Db::name('admin_shop')->where($where)->order('id desc')->field('id,shopname,map_address,pic_url')->page($page)->paginate(10)->each(function ($item,$key)use($url){
            $item['pic_url']=$url.$item['pic_url'];
            return $item;
        });
        return returnJson(200,'获取成功',$shop);
    }

}
